<?php
/**
 * 侧边栏组件和页面模块
 */

function widget_blogger($w_info) {
	global $user_cache;
	$name = $user_cache['email'] != '' ? '<a href="mailto:'.$user_cache['email'].'">'.$user_cache['nickname'].'</a>' : $user_cache['nickname'];?>
	<div class="widget">
		<div class="widget_title"><?php echo $w_info['title'];?></div>
		<ul id="bloggerinfo">
			<div id="bloggerinfoimg">
				<?php
				if (!empty($user_cache['photo']['src'])) { ?>
					<img src="<?php echo BLOG_URL.$user_cache['photo']['src'];?>" width="<?php echo $user_cache['photo']['width'];?>" height="<?php echo $user_cache['photo']['height'];?>" alt="blogger"/>
					<?php
				}?>
			</div>
			<li>作者：<?php echo $name;?></li>
			<li><?php echo $user_cache['des'];?></li>
		</ul>
	</div>
	<?php
}?>

<?php
//widget:标签
function widget_tag($w_info) {
	global $tag_cache;?>
	<div class="widget"><div class="widget_title"><?php echo $w_info['title'];?></div>
	<ul id="blogtags">
		<?php
		foreach($tag_cache as $value) {?>
			<li>
			<a href="<?php echo BLOG_URL.'/?tag='.$value['name'];?>"><?php echo $value['name'];?> (<?php echo $value['count'];?>)</a></span></li>
			<?php
		}?>
	</ul></div>
	<?php
}?>

<?php
//widget: 最新评论
function widget_newcomm($w_info) {
	global $com_cache, $blogUrl;?>
	<div class="widget"><div class="widget_title" onclick="showhidediv('newcomment')"><?php echo $w_info['title'];?></div>
	<ul id="newcomment"><?php
		foreach ($com_cache as $value) {
			$url = $blogUrl.'/?article='.$value['aid'].'#'.$value['id'];
			?>
			<li id="comment"><a href="<?php echo $value['url'];?>"><?php echo $value['nickname'];?></a>&nbsp;在《<?php echo $value['title'];?>》写到：
			<a href="<?php echo $url;?>"><?php echo $value['content'];?></a></li>
			<?php
		}?>
	</ul></div>
	<?php
}

//widget : 搜索
function widget_search($w_info) {
	?>
	<div class="widget">
	<div class="widget_title" onclick="showhidediv('logsearch')"><?php echo $w_info['title'];?></div>
	<ul id="logsearch">
	<li>
	<form name="keyform" method="get" action="<?php echo BLOG_URL;?>/index.php">
		<input name="keyword" type="text" value="" style="width:120px;border:solid #CCC 1px;" />
		<input type="submit" id="logsearch_logsearch" value="搜索" onclick="return keyw()" />
	</form></li></ul></div>
	<?php
}

//widget : 归档
function widget_archive($w_info) {
	global $dang_cache;
	?>
	<div class="widget">
	<div class="widget_title" onclick="showhidediv('record')"><?php echo $w_info['title'];?></div>
	<ul id="record">
	<?php
	foreach ($dang_cache as $value) {
		?>
		<li><a href="<?php echo BLOG_URL.$value['url'];?>"><?php echo $value['record'];?>(<?php echo $value['lognum'];?>)</a></li>
		<?php
	}?>
	</ul></div>
	<?php
}

//widget : 自定义组件
function widget_custom_text($w_info) {
	?>
	<div class="widget">
	<div class="widget_title"><?php echo $w_info['title'];?></div>
	<div><?php echo $w_info['content'];?></div></div>
	<?php
}

//widget : 链接
function widget_link($w_info) {
	global $link_cache;
	?>
	<div class="widget">
	<div class="widget_title" onclick="showhidediv('link')"><?php echo $w_info['title'];?></div>
	<ul id="link">
	<?php
	foreach ($link_cache as $value) {
		?>
		<li><a href="<?php echo $value['url'];?>" title="<?php echo $value['name'];?>" target="_blank"><?php echo $value['name'];?></a></li>
		<?php
	}?>
	</ul></div>
	<?php
}

//widget : 博客信息
function widget_bloginfo($w_info) {
	global $sta_cache, $view_count;
	?>
	<div class="widget">
	<div class="widget_title" onclick="showhidediv('bloginfo')"><?php echo $w_info['title'];?></div>
	<ul id="bloginifo">
	<li>日志数量：<?php echo $sta_cache['lognum'];?></li>
	<li>评论数量：<?php echo $sta_cache['comnum'];?></li>
	<li>今日访问：<?php echo $view_count['viewcount_day'];?></li>
	<li>昨日访问：<?php echo $view_count['viewcount_yesterday'];?></li>
	<li>总访问量：<?php echo $view_count['viewcount_all'];?></li>
	</ul></div>
	<?php
}

// 博客管理
function widget_admin($w_info) {
	global $blogUrl;
	?>
	<div class="widget">
	<div class="widget_title" onclick="showhidediv('bloginfo')"><?php echo $w_info['title'];?></div>
	<table width="100%"><tr><td align="left"><a href="<?php echo $blogUrl;?>/admin/new_edit_article.php">发表文章</a></td>
	<td align="right"><a href="<?php echo $blogUrl;?>/admin/index.php">后台管理</a></td></tr></table></div>
	<?php
}

//blog: 编辑
function editflg($logid) {
	$editflg = isLogin() ? '<a href="'.BLOG_URL.'/admin/new_edit_article.php?action=edit&aid='.$logid.'">编辑</a>' : '';
	echo $editflg;
}

//blog: 日志标签
function blog_tag($blogid) {
	global $logs, $log_data;
	if ($logs) {
		echo '&nbsp;';
		if (!empty($logs[$blogid]['tags'])) {
			$tag = '标签：';
			foreach ($logs[$blogid]['tags'] as $value) {
				$tag .= '&nbsp;<a href="'.BLOG_URL.'/'.$value.'-tag.html">'.$value.'</a>';
			}
			echo $tag;
		}
	} else if ($log_data) {
		echo '&nbsp;';
		if (!empty($log_data['tags'])) {
			$tag = '标签：';
			foreach ($log_data['tags'] as $value) {
				$tag .= '&nbsp;<a href="'.BLOG_URL.'/'.$value.'-tag.html">'.$value.'</a>';
			}
			echo $tag;
		}
	}
}

//blog : 日志作者
function blog_author($uid) {
	global $user_cache,$DB;
	$author = $user_cache['nickname'];
	echo '<a href="'.BLOG_URL.'/?author='.$uid.'">'.$author.'</a>';
}

//blog : 相邻日志
function neighbor_log() {
	?>
	<div id="prev_log"><?php
	global $prevLog, $nextLog;
	if ($prevLog) {
		?>
		&laquo;&nbsp;<a href="<?php echo BLOG_URL.'/'.$prevLog['id'];?>-article.html">上一篇&nbsp;《<?php echo $prevLog['title'];?>》</a>
		<?php
	}?></div><div id="next_log"><?php
	if ($nextLog) {
		?>
		<a href="<?php echo BLOG_URL.'/'.$nextLog['id'];?>-article.html">《<?php echo $nextLog['title'];?>》&nbsp;下一篇</a>&nbsp;&raquo;
		<?php
	}?></div><?php
}

//blog: 博客评论列表
function blog_comments() {
	global $comments;
	?>
	<div id="comments">
	<?php
	if ($comments) {
		?>
		<b>评论：</b><a href="comment"></a><br />
		<?php
	} else {
		?><strong>暂无评论</strong>
		<?php
	}
	foreach ($comments as $comment) {
		$comment['user'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank">'.$comment['nickname'].'</a>' : $comment['nickname'];
		?>
		<div class="comment">
			<div class="content_comment"><?php echo $comment['content'];?></div>
			<div class="footer_comment">
				<a name="<?php echo $comment['id'];?>_comment">#<?php echo $comment['id'];?></a>&nbsp;
				昵称：<?php echo $comment['user'];?>&nbsp;
				发表日期：<?php echo date('n月j日 G:i Y年',$comment['time_date']+3600*$timezone);?>
			</div>
		</div>
		<?php
	}
	?>
	</div>
	<?php
}

//blog: 发表评论表单
function blog_comments_post() {
	global $logid,$ckname,$ckmail,$ckurl,$checkimg,$allow_remark;
	?>
	<div id="comment_post">
		<strong>发表评论</strong>
		<form method="post" name="commentform" action="http://<?php echo $_SERVER['HTTP_HOST'].rebuild_uri(array('action'=>'addcom'));?>">
		<p>
		<input type="hidden" name="gid" value="<?php echo $logid;?>" size="22" tabindex="1" />
		<input type="text" name="nickname" maxlength="49" value="<?php echo $ckname;?>" size="22" tabindex="1" />
		<label for="author"><small>昵称</small></label></p>
		<input type="text" name="commail" maxlength="128" value="<?php echo $ckmail;?>" size="22" tabindex="2" />
		<label for="email"><small>邮件地址 (选填)</small></label>
		<p>
		<input type="text" name="comurl" maxlength="128" value="<?php echo $ckurl;?>" size="22" tabindex="3" />
		<label for="url"><small>个人主页 (选填)</small></label></p>
		<textarea name="comment" id="content_fcomment" rows="10" tabindex="4"></textarea>
		<div id="div_submit_fcomment">
			<?php echo $checkimg;?>&nbsp;&nbsp;
			<input type="submit" id="submit_fcomment" value="发表评论" onclick="return checkform()" tabindex="6" />
		</div>
		</form>
	</div>
	<?php
}
